package sim.util;

import org.junit.Assert;
import org.junit.Test;

/**
 * Unit test for the Bag utility class.
 *
 * @author sbeitzel
 * @version $Revision: $
 */
public class TestBag {

    @Test
    public void testAdd() {
        Bag b = new Bag();
        Assert.assertTrue("New bag isn't empty", b.isEmpty());
        b.add(Integer.valueOf(7));
        Assert.assertEquals("Bag doesn't contain the expected number of elements", 1, b.size());
        Assert.assertTrue("Bag doesn't contain the object just added", b.contains(Integer.valueOf(7)));
    }

    @Test
    public void testAddAll() {
        Bag b = new Bag();
        b.add(Integer.valueOf(7));
        b.add(Integer.valueOf(11));
        b.add(Integer.valueOf(13));
        b.add(Integer.valueOf(17));

        Bag targetBag = new Bag();
        targetBag.add(Integer.valueOf(2));
        targetBag.add(Integer.valueOf(4));

        targetBag.addAll(1, b);

        Assert.assertEquals(Integer.valueOf(7), targetBag.objs[1]);

        Integer [] ira = new Integer[] {Integer.valueOf(3), Integer.valueOf(5), Integer.valueOf(7)};
        targetBag.addAll(0, ira);

        for (int i=0; i<ira.length; i++) {
            Assert.assertEquals("Array version of addAll at index 0 failed", ira[i], targetBag.objs[i]);
        }
    }
}
